package api

import (
	"api_gateway/basic/config"
	__ "api_gateway/basic/proto"
	"api_gateway/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func CreateOrder(c *gin.Context) {
	var req request.CreateOrder
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    http.StatusBadRequest,
			"message": "验证失败",
			"data":    nil,
		})
		return
	}
	order, err := config.HopeClient.CreateOrder(c, &__.CreateOrderReq{
		Title:     req.Title,
		TeacherId: int64(req.TeacherId),
		StartTime: req.StartTime,
		EndTime:   req.EndTime,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    http.StatusBadRequest,
			"message": "创建订单失败",
			"data":    err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    http.StatusBadRequest,
		"message": "创建订单成功",
		"data":    order,
	})
}
